<template>
  <FormView not-form form-width="100%">
    <p>{{ respType }}</p>
    <p>{{ JSON.stringify(respSubjects) }}</p>
    <div>
      <ElButton @click="showMenu">显示菜单</ElButton>
      <ContextMenu ref="contextMenu" :list="menu" @on-item-click="onMenuItemClick" />
    </div>
    <div style="overflow-x: hidden">
      <ElRow :gutter="200">
        <ElCol :span="12"> 1212 </ElCol>
        <ElCol :span="12"> 1212 </ElCol>
        <ElCol :span="12"> 1212 </ElCol>
        <ElCol :span="12"> 1212 </ElCol>
        <ElCol :span="12"> 1212 </ElCol>
        <ElCol :span="12"> 1212 </ElCol>
      </ElRow>
    </div>
    <div class="doodle">
      <div style="padding: 50px">
        <SignPanel v-model="sign" />
      </div>
      <AddressInput
        v-model="value11"
        :options="treeOptions"
        style="margin-top: 10px; margin-right: 10px; margin-left: 10px" />
      <div class="flex-row" style="padding: 50px">
        <div class="square-icon square-icon__task">任务</div>
        <div class="square-icon square-icon__message">消息通知</div>
        <div class="square-icon square-icon__im">即时沟通</div>
        <div class="square-icon square-icon__file">资料快传</div>
      </div>
      <div style="padding: 50px">
        <div class="task-card">
          <div class="label">
            <span class="label-content">信息填报类 / 多人共享协作</span>
            <span class="label-angle"></span>
          </div>
          <div class="task-card-content">
            <div class="card-header task-doing">
              <span class="flex-item-relative task-status">已逾期</span>
              <span class="flex-item task-left-day">剩余<span class="task-status-text">-3</span>天 </span>
            </div>
            <p class="card-title">
              2020年度全省高校党委数据履行全面从严治党责任述职评议考核工作2020年度全省高校党委数据履行全面从严治党责任述职评议考核工作
            </p>
            <div class="card-column">
              <span class="card-link">任务进度</span>
              ：
              <ElProgress :percentage="50" class="flex-item" />
            </div>
            <div class="card-footer">
              <span style="margin-right: 14px">
                <i class="el-icon-lx-comment"></i>
                <span class="card-link" style="padding-left: 4px">留言互动(2)</span>
              </span>
              <span>
                <i class="el-icon-lx-exit"></i>
                <span class="card-link" style="padding-left: 4px">进入任务</span>
              </span>
            </div>
          </div>
        </div>
      </div>

      <div style="width: 100%; margin-top: 10px">
        <Attachment style="width: 40%; margin: 10px auto" unid="736214bd76c215c527ac9fc4c979768c" />
        <Attachment disabled style="width: 40%; margin: 10px auto" unid="736214bd76c215c527ac9fc4c979768c" />
      </div>
      <div style="width: 100%; margin-top: 10px">
        <EditableProgress v-model="percent" style="width: 800px; margin: 0 auto" />
        <EditableProgress v-model="percent" :max="80" style="width: 800px; margin: 10px auto 0" />
      </div>
      <ElProgress v-show="showProgress" :percentage="percent" style="width: 100%" />
      <ElUpload
        ref="upload"
        :action="action"
        auto-upload
        :before-upload="beforeUpload"
        :data="{ unid: '' }"
        :headers="headers"
        :on-error="onError"
        :on-progress="onProgress"
        :on-success="onSuccess"
        :show-file-list="false"
        class="upload-demo">
        <template #trigger>
          <ElButton icon="el-icon-upload" size="small" type="plain" />
        </template>
      </ElUpload>
      <Tooltip />
      <Emotion />
      <NoticePop />
      <div style="width: 100%; padding: 20px">
        <ElButton type="primary" @click="visible = true">缓存对话框内容</ElButton>
        <ElButton type="primary" @click="visible1 = true">不缓存对话框内容</ElButton>
        <ElButton type="primary" @click="visible3 = true">测试注册</ElButton>
      </div>
      <XDialog
        :component="import('@/views/playground/TestComp')"
        :message="message"
        :visible.sync="visible"
        title="缓存对话框内容"
        @confirm="success" />
      <XDialog
        :cache="false"
        :component="() => import('@/views/playground/TestComp')"
        :footer="false"
        :message="message"
        :visible.sync="visible1"
        title="不缓存对话框内容"
        @confirm="success" />
      <XDialog
        :component="$options.components.Emotion"
        :visible.sync="visible3"
        height="auto"
        title="测试注册"
        width="400px" />
    </div>
    <div class="doodle">
      <ElForm ref="form" style="width: 100%" :model="entity">
        <DynamicTable :key="key" v-model="entity.rows" :columns="columns" :disabled="disabled" />
      </ElForm>
      <ElButton type="primary" style="margin: 10px" @click="validate">校验</ElButton>
      <ElButton type="primary" style="margin: 10px" @click="disabled = !disabled">只读</ElButton>
      <ElButton type="primary" style="margin: 10px" @click="getColumns">更新列配置</ElButton>
    </div>
  </FormView>
</template>

<script>
  import Emotion from '@/views/playground/widgets/Emotion'
  import Tooltip from '@/views/playground/widgets/Tooltip'
  import { getUploadUrl, getHeader } from '@/api/attachment/attachment'
  import { delay } from '@web-utils/core'

  const action = getUploadUrl()
  const headers = getHeader()

  export default {
    name: 'Doodle',
    components: {
      Tooltip,
      Emotion
    },
    data() {
      const columns = []

      for (let i = 1; i < 20; i++) {
        const column = {
          label: `列名${i}`,
          type: 'text'
        }
        columns.push(column)
      }

      return {
        respType: '',
        respSubjects: [],
        menu: [
          {
            text: '下载',
            icon: 'el-icon-setting'
          },
          {
            text: '移动',
            icon: 'el-icon-setting'
          },
          {
            text: '复制',
            icon: 'el-icon-setting'
          },
          {
            text: '删除',
            icon: 'el-icon-setting'
          },
          {
            text: '重命名',
            icon: 'el-icon-setting'
          },
          {
            text: '推送到',
            icon: 'el-icon-setting'
          },
          {
            text: '更多',
            children: [
              {
                text: '收藏',
                children: [
                  {
                    text: '收藏'
                  },
                  {
                    text: '编辑标签'
                  }
                ]
              },
              {
                text: '编辑标签'
              }
            ]
          }
        ],
        sign: '',
        visible: false,
        disabled: false,
        visible1: false,
        visible3: false,
        value11: {
          address: ['广东省', '广州市', '天河区'],
          detailAddress: '54645645'
        },
        treeOptions: [],
        action,
        headers,
        showProgress: false,
        percent: 70,
        message: 'Hello World !',
        columns,
        key: 1
      }
    },
    computed: {
      entity() {
        const model = {}
        this.columns.forEach(value => {
          model[value.prop] = (value.props || {}).value || value.value
        })

        return {
          rows: [model]
        }
      }
    },
    methods: {
      showMenu(event) {
        this.$refs.contextMenu.show(event)
      },
      onMenuItemClick(item, indexList) {
        // console.log(item)
        // console.log(indexList)
      },
      getColumns() {
        this.columns = this.$refs.cEditor.getColumns()
        this.key++
      },
      validate() {
        this.$refs.form.validate(async valid => {
          if (valid) {
            console.log(this.entity)
          }
        })
      },
      success(data) {
        this.$notify({ type: 'success', title: 'Doodle', message: `onSuccess: ${JSON.stringify(data)}` })
      },
      beforeUpload(file) {
        this.showProgress = true
        return true
      },
      onProgress(event, file, fileList) {
        this.percent = event.percent
      },
      async onSuccess(response, file, fileList) {
        console.log(response)
        this.$refs.upload.clearFiles()
        await delay(1000)
        this.showProgress = false
      },
      async onError(event, file, fileList) {
        console.log(event)
        await delay(1000)
        this.showProgress = false
      }
    }
  }
</script>

<style lang="scss" scoped>
  .doodle {
    display: flex;
    flex-flow: row wrap;
    align-items: flex-start;
    justify-content: flex-start;

    .upload-demo {
      padding-top: 10px;
      padding-left: 10px;
    }
  }

  $border-radius-size: 10px;

  ::v-deep.task-card {
    width: 253px;

    .label {
      display: flex;
      align-items: center;
      height: 26px;
      border-top-left-radius: $border-radius-size;
    }

    .label-content {
      z-index: 1;
      display: inline-flex;
      align-items: center;
      min-width: 110px;
      height: 100%;
      padding-left: 10px;
      font-size: 12px;
      background-color: #caecfe;
      border-top: 1px solid var(--border-color);
      border-left: 1px solid var(--border-color);
      border-top-left-radius: $border-radius-size;
    }

    .label-angle {
      position: relative;
      right: 20px;
      display: inline-block;
      width: 60px;
      height: 100%;
      background-color: #caecfe;
      border-top: 1px solid var(--border-color);
      border-right: 1px solid var(--border-color);
      border-left: 1px solid var(--border-color);
      transform: skewX(45deg);
    }

    .task-card-content {
      padding: 6px;
      border: 1px solid #cfcfcf;
      border-top-right-radius: $border-radius-size;
      border-bottom-right-radius: $border-radius-size;
      border-bottom-left-radius: $border-radius-size;
      box-shadow: 0 2px 5px #c9c5c5;
    }

    .card-header {
      display: flex;
      align-items: center;
      padding: 10px 0;
    }

    .card-column {
      display: flex;
      align-items: center;
      padding: 10px 0;

      .el-progress-bar__outer {
        height: 12px !important;
        border-radius: 0;
      }

      .el-progress-bar__inner {
        border-radius: 0;
      }
    }

    .card-link {
      padding-bottom: 1px;
      border-bottom: 1px solid #808080;
      cursor: pointer;
    }

    .card-title {
      color: #5f5f5f;
      font-weight: bold;

      @include ellipsis(2);
    }

    .card-footer {
      padding: 10px;
      color: #808080;
      font-size: 12px;
      text-align: right;
    }

    .task-status-text {
      padding: 0 6px;
      font-weight: bold;
      font-size: 16px;
    }

    .task-left-day {
      padding-right: 10px;
      text-align: right;
    }

    .task-status {
      position: relative;
      display: flex;
      align-items: center;

      &::before {
        display: inline-block;
        width: 14px;
        height: 14px;
        margin-right: 6px;
        background-color: #14ca7a;
        border-radius: 2px;
        content: '';
      }
    }

    .task-done {
      .task-status::before {
        background-color: #d7d7d7;
      }
    }

    .task-doing {
      .task-status::before {
        background-color: #14ca7a;
      }
    }

    .task-waiting-close {
      .task-status::before {
        background-color: var(--color-primary);
      }
    }

    .task-warning {
      .task-status::before {
        background-color: #feae3d;
      }
    }

    .task-overdue {
      .task-status::before {
        background-color: #ff686e;
      }

      .task-status-text {
        color: #ff686e;
      }
    }
  }

  .square-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    margin-left: 20px;
    overflow: hidden;
    color: white;
    font-size: 15px;
    line-height: 1.2;
    text-align: center;
    border-radius: 4px;

    &__message {
      background: radial-gradient(circle farthest-side at 50% 0, #fad5a6 0%, #fda53a 100%);
    }

    &__task {
      background: radial-gradient(circle farthest-side at 50% 0, #cfeaff 0%, #5eb0ff 100%);
    }

    &__im {
      background: radial-gradient(circle farthest-side at 50% 0, #9deeaf 0%, #56d479 100%);
    }

    &__file {
      background: radial-gradient(circle farthest-side at 50% 10%, #bee9ff 0%, #38d8f9 100%);
    }
  }
</style>
